package com.gitee.huanminabc.jcommon.fastjson;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.serializer.SerializeWriter;
import com.gitee.huanminabc.jcommon.model.FeeRate;

import java.io.IOException;
import java.lang.reflect.Type;

/**
 * @description: 序列化如果是金额类型，则序列化为元,保留2位小数
 *  数据库存储用decimal
 * @author: huanmin
 * @create: 2025-04-17 22:00
 **/
public class FeeRateObjectWriter implements ObjectSerializer {
    @Override
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
        SerializeWriter out = serializer.getWriter();
        if (object == null) {
            out.writeNull();
            return;
        }
        FeeRate money = (FeeRate) object;
        out.writeString(String.valueOf(money.intValue()));
    }
}
